﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Zo.Config;
using Zo.Http;
using Zo.Models;
using ZoLone.Models;
using ZoLone.Zo.Extensions;

namespace ZoLone.Controllers
{
    public class HomeController : Controller
    {
        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            var _IExceptionHandlerFeature = HttpContext.Features.Get<IExceptionHandlerFeature>();
            var _Error = _IExceptionHandlerFeature?.Error;
            var IsAjaxRequest = Request.IsAjax();
            var _ErrorModel = ErrorModel.Instance;
            //判断是否是自定义异常类型
            if (_Error is ErrorBox)
            {
                HttpContext.Response.StatusCode = 200;
                if (_ErrorModel.status == (int)ErrorMsgStatus.Custom) return Json(_ErrorModel.Data);
                return Json(ErrorModel.Instance);
            }
            else
            {
                //写日志
                _ErrorModel = new ErrorModel(_Error);
                if (IsAjaxRequest) return Json(_ErrorModel);
                return View(AppConfig.options.ErrorPageUrl, _ErrorModel);
            }
        }

        public IActionResult Index()
        {
            return RedirectToAction("Index", "Home", new { area = "Admin" });
        }
    }

     
}
